<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://displaytag.sf.net" prefix="display"%>
<%@ taglib uri="http://www.springframework.org/security/tags" prefix="ss"%>

<jsp:include page="../header.jsp" />
<script type="text/javascript">
function giveBack(bookId){
	var userId = ${user.id};
	window.location = "/isLibrary/users/giveBack.do?userId="+userId+"&bookId="+bookId;
}

function borrow(bookId){
	var userId = ${user.id};
	window.location = "/isLibrary/users/borrowFromReservation.do?userId="+userId+"&bookId="+bookId;
}

function deleteReservation(bookId){
	var userId = ${user.id};
	window.location = "/isLibrary/users/deleteReservation.do?userId="+userId+"&bookId="+bookId;
}
</script>
<div id="content">
	<div id="topstory" class="box">
		<h1>
			<fmt:message key="user.title.show" >
				<fmt:param value="${user.jmeno} ${user.prijmeni }"/>
			</fmt:message>
		</h1>
	</div>
	<div class="padding">
		<c:choose>
			<c:when test="${ user != null}">
			<h4><fmt:message key="label.user.details"/></h4>
				<table border="0" cellspacing="5" cellpadding="0" width="100%" class="formTable tplBorder">
					<tr>
						<td width="15%"></td>
						<td width="35%"></td>
						<td width="15%"></td>
						<td width="35%"></td>
					</tr>
					<tr>
						<td class="label"><fmt:message key="user.name" /></td>
						<td class="valueOutView"><c:out value="${user.jmeno }" /></td>
						<td class="label"><fmt:message key="user.surname" /></td>
						<td class="valueOutView"><c:out value="${user.prijmeni }" /></td>
					</tr>
					<tr>
						<td class="label"><fmt:message key="user.login" /></td>
						<td class="valueOutView"><c:out value="${user.login}" /></td>
						<td class="label"><fmt:message key="user.password" /></td>
						<td class="valueOutView">*********</td>
					</tr>
					<tr>
						<td class="label"><fmt:message key="user.street" /></td>
						<td class="valueOutView"><c:out value="${user.ulice}" /></td>
						<td colspan="2"/>
					</tr>
					<tr>
						<td class="label"><fmt:message key="user.mesto" /></td>
						<td class="valueOutView"><c:out value="${user.mesto }" /></td>
						<td class="label"><fmt:message key="user.psc" /></td>
						<td class="valueOutView"><c:out value="${user.psc }" /></td>
					</tr>
					<tr>
						<td class="label"><fmt:message key="user.obdobi.od" /></td>
						<td class="valueOutView"><c:out value="${user.obdobiOd }" /></td>
						<td class="label"><fmt:message key="user.obdobi.do" /></td>
						<td class="valueOutView"><c:out value="${user.obdobiDo }" /></td>
					</tr>
					<c:if test="${user.admin }">
						<tr>
							<td class="label"><fmt:message key="user.rodne.cislo" /></td>
							<td class="valueOutView"><c:out value="${user.rodneCislo }" /></td>
							<td colspan="2" />
						</tr>
						<tr>
							<td class="label"><fmt:message key="user.zamestnan.od" /></td>
							<td class="valueOutView"><c:out value="${user.zamestnanOd }" /></td>
							<td class="label"><fmt:message key="user.zamestnan.do" /></td>
							<td class="valueOutView"><c:out value="${user.zamestnanDo }" /></td>
						</tr>
					</c:if>
				</table>
				<h4><fmt:message key="label.borrowed.books"/></h4>
				<fieldset>
					<display:table id="data" name="pujceneKnihy" requestURI="/users/show.do?userId=${user.id }"
						decorator="cz.boxdesign.library.web.decorator.BookTableDecorator">
						<ss:authorize access="hasRole('ROLE_ADMIN')">
							<display:column property="giveBackUrl" titleKey="users.books.give.back" sortable = "false"/>
						</ss:authorize>
						<display:column property="showUrl" title="Show" sortable="false" />
						<display:column property="nazev" title="Nazev" sortable="true" />
						<display:column property="oddeleniLink" title="Oddeleni" sortable="true" />
						<display:column property="nakladatelstviLink" title="Nakladatelstvi" sortable="true" />
					</display:table>
				</fieldset>
				<h4><fmt:message key="label.reserved.books"/></h4>
				<fieldset>
					<display:table id="data" name="rezervovaneKnihy" requestURI="/users/show.do?userId=${user.id }"
						decorator="cz.boxdesign.library.web.decorator.BookTableDecorator">
						<ss:authorize access="hasRole('ROLE_ADMIN')">
							<display:column property="borrowUrl" title="Show" sortable="false" />							
						</ss:authorize>
						<display:column property="deleteReservationUrl" title="Show" sortable="false" />
						<display:column property="showUrl" title="Show" sortable="false" />
						<display:column property="nazev" title="Nazev" sortable="true" />
						<display:column property="oddeleniLink" title="Oddeleni" sortable="true" />
						<display:column property="nakladatelstviLink" title="Nakladatelstvi" sortable="true" />
					</display:table>
				</fieldset>
			</c:when>
			<c:otherwise>
				<div class="ui-widget">
					<div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
						<p>
							<span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span> <strong>Alert:</strong>
							<c:out value="${error }" />
							. Please contact administrator.
						</p>
					</div>
				</div>

			</c:otherwise>
		</c:choose>
	</div>
	<!-- /padding -->
</div>
<!-- /content -->
<jsp:include page="side-menu.jsp" />
<jsp:include page="../foother.jsp" />
